/*
 * Inventory.java
 * Team qq 2011
 */
package com.google.code.timetrail.backend;
/**
 * This class provides an object to simulate and inventory 
 * and does things like adding and subtracting items from
 * the inventory 
 * @author Anurrag
 * @version 1.01
 * Removed magic numbers and made it so that inventories get 
 * instantiated as empty and are filled in based
 * on what Persons do
 *
 *
 */
public class Inventory {
    /*
     * TODO consider how oxen type items (engines I guess) would work, IE 
     * would they be in the ship or would they be in the inventory
     */
	
	
	private Item money, fuelCells, food, hullParts, fCapacitors, engines, timeSuits, timeBulletBills;

	private static final int INV_CAPACITY = 3500;

	private static final int INV_MIN = 0;

	private int invWeight;
	
	public Inventory(){
		invWeight = 0;
		
		money = new Money();
		fuelCells = new FuelCell();
		food = new Food();
		hullParts = new HullPart();
		fCapacitors = new FluxCapacitor();
		engines = new Engine();
		timeSuits = new TimeSuit();
		timeBulletBills = new TimeBulletBill();


	}

	/**
	 * adds an item to the inventory without dealing with things like "cost" and "money"
	 * things like weight and capacity will still affect it
	 * @param amount how many items to be received 
	 * @param item what kind of item to be received
	 * @return true if an item is added and false if it is not
	 */
	public boolean addItem(int amount, Item item){
		boolean addConfirm = item.addCurrentAmount(amount);
		if(addConfirm && invWeight + item.getWeight() < INV_CAPACITY 
				&& invWeight + item.getWeight() > INV_MIN){
			invWeight += (amount * item.getWeight());
			return true;
		}
		else{
			return false;
		}
	}
	
	public boolean addItem(int amount, Item item, boolean dryRunFlag){
		boolean addConfirm = item.addCurrentAmount(amount, dryRunFlag);
		if(addConfirm && invWeight + item.getWeight() < INV_CAPACITY 
				&& invWeight + item.getWeight() > INV_MIN){
			return true;
		}
		else{
			return false;
		}
	}

	/**
	 * remove an item from the inventory without dealing with money
	 * still refactors weight when removed
	 * this is basically a call to add item, but with a more intuitive name
	 * @param amount the amount of items to remove from the inventory  
	 * @param item the type of item to remove
	 * @return true if an item is removed and false if it is not
	 */
	public boolean removeItem(int amount, Item item){
		if(amount < 0){
			return false;
		}
		else{
			return addItem((amount * -1), item);
		}
	}
	
	public boolean removeItem(int amount, Item item, boolean dryRunFlag){
		if(amount < 0){
			return false;
		}
		else{
			return addItem((amount * -1), item, dryRunFlag);
		}
	}

	/**
	 * returns the real weight of the inventory
	 * @return the inventory's current weight
	 */
	public int getInvWeight() {
		return invWeight;
	}
	
	/**
	 * sets the inventory weight, if the weight would not work return false
	 * @param invWeight the weight to set the inventory to
	 * @return true if it would work, false if it does not
	 */
	public void setInvWeight(int invWeight) {
			this.invWeight = invWeight;
		
	}

	/**
	 * WE GETTIN MONEY UP IN HERE HOMIE
	 * @return money
	 */
	public Item getMoney() {
		return money;
	}

	public Item getFuelCells() {
		return fuelCells;
	}

	public Item getFood() {
		return food;
	}

	public Item getHullParts() {
		return hullParts;
	}

	public Item getfCapacitors() {
		return fCapacitors;
	}

	public Item getEngines() {
		return engines;
	}

	public Item getTimeSuits(){
		return timeSuits;
	}

	public Item getTimeBulletBills(){
		return timeBulletBills;
	}

	/**
	 * @return the iNV_CAPACITY
	 */
	public int getCapacity() {
		return INV_CAPACITY;
	}
	
	
	
}




